<?php
//模式1 简单模式（单生产 单消费）
//简单的发送与接受，没有特别的处理
require_once __DIR__ . '/../vendor/autoload.php';
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;


$connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest');
$channel = $connection->channel();

// $msg = new AMQPMessage('Hello World!');
// $channel->basic_publish($msg,'','hello');
for ($i = 0; $i < 10; $i++) {
    $body = "写入'Hello World!' 时间为:".date("Y-m-d H:i:s",time());
    $message = new AMQPMessage($body);
    $channel->basic_publish($message,'', "hello");
    sleep(1);

}
//websocket
echo "写入'Hello World!' 时间为:".date("Y-m-d H:i:s",time())." \n";

$channel->close();
$connection->close();